<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>警报通知 | 智能家居控制</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <style>
      /* ===== 新增背景设置 ===== */
    body {
      font-family:"Segoe UI",sans-serif;
      margin:0;
      min-height:100vh;
      /* 背景图片设置 */
      background: url('{% static "images/background.jpg" %}') no-repeat center center fixed;
      background-size: cover;
      position: relative;
    }
    /* 半透明遮罩层 */
    body::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(255, 255, 255, 0.7);  /* 白色半透明遮罩 */
      z-index: 0;
    }
    /* 确保内容在遮罩层上方 */
    .wrapper {
      position: relative;
      z-index: 1;
      max-width:960px;
      margin:40px auto;
      background:#fff;
      padding:24px 32px;
      border-radius:16px;
      box-shadow:0 6px 18px rgba(0,0,0,.12);
    }
    .container {
      max-width: 600px;
      margin: 40px auto;
      background: white;
      padding: 30px;
      border-radius: 16px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      text-align: center;
    }
    .alert-icon {
      font-size: 60px;
      color: #ef4444;
      margin-bottom: 20px;
    }
    h1 {
      color: #ef4444;
      margin-bottom: 20px;
    }
    .alert-message {
      background: #fee2e2;
      padding: 15px;
      border-radius: 8px;
      margin-bottom: 25px;
      text-align: left;
    }
    .alert-detail {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
    }
    .alert-detail i {
      margin-right: 10px;
      font-size: 20px;
    }
    .btn {
      background: #2563eb;
      color: white;
      border: none;
      border-radius: 8px;
      padding: 12px 24px;
      font-size: 16px;
      cursor: pointer;
      transition: 0.2s;
      margin: 10px;
    }
    .btn:hover {
      background: #1e40af;
    }
    .btn-secondary {
      background: #e5e7eb;
      color: #4b5563;
    }
    .btn-secondary:hover {
      background: #d1d5db;
    }
    .confirmation-message {
      margin-top: 15px;
      color: #22c55e;
      font-weight: bold;
      animation: fadeIn 0.5s;
    }
    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="alert-icon">
      <i class="fas fa-exclamation-triangle"></i>
    </div>
    <h1>环境异常警报</h1>

    <div class="alert-message" id="alertDetails">
      <!-- 动态填充警报详情 -->
    </div>

    <div id="actionButtons">
      <button class="btn" onclick="acknowledgeAlert()">
        <i class="fas fa-check"></i> 确认并返回
      </button>
      <button class="btn btn-secondary" onclick="goToControlPage()">
        <i class="fas fa-home"></i> 立即返回
      </button>
    </div>

    <div id="confirmationMessage" class="confirmation-message" style="display:none;">
      <i class="fas fa-check-circle"></i> 正在返回控制页面...
    </div>
  </div>

  <script>
    // 从URL参数获取警报信息
    const urlParams = new URLSearchParams(window.location.search);
    const temp = urlParams.get('temp');
    const humi = urlParams.get('humi');

    // 显示警报详情
    function displayAlertDetails() {
      const alertDetailsEl = document.getElementById('alertDetails');
      let alertMessages = [];

      if (temp > 30) {
        alertMessages.push(`
          <div class="alert-detail">
            <i class="fas fa-thermometer-full"></i>
            <span>温度过高: ${temp}°C (建议保持16-30°C)</span>
          </div>
        `);
      }

      if (humi > 80) {
        alertMessages.push(`
          <div class="alert-detail">
            <i class="fas fa-tint"></i>
            <span>湿度过高: ${humi}% (建议保持35-80%)</span>
          </div>
        `);
      }

      if (humi < 35) {
        alertMessages.push(`
          <div class="alert-detail">
            <i class="fas fa-tint"></i>
            <span>湿度过低: ${humi}% (建议保持35-80%)</span>
          </div>
        `);
      }

      alertDetailsEl.innerHTML = alertMessages.join('');
    }

// 确认警报
function acknowledgeAlert() {
  localStorage.setItem('lastAlertAck', new Date().toISOString());

  document.getElementById('actionButtons').style.display = 'none';
  document.getElementById('confirmationMessage').style.display = 'block';

  setTimeout(() => {
    // 使用Django的URL反向解析
    window.location.href = "{% url 'index' %}";
  }, 800);
}

// 立即返回
function goToControlPage() {
  window.location.href = "{% url 'index' %}";
}

    // 立即返回控制页
    function goToControlPage() {
      const returnUrl = new URL('index.html', window.location.origin);
      window.location.href = returnUrl.href;
    }

    // 页面加载时显示警报
    displayAlertDetails();
  </script>
</body>
</html>